package xyz.naokeziteng.leetcode;

import java.util.Stack;

/**
 * @author hawk
 * @date 2022/8/10
 * @desc 回文链表
 **/
public class PalindromicLinkedList {

    public static boolean isPalindrome(ListNode head) {
        if (head.next == null) {
            return true;
        }
        Stack<ListNode> stack = new Stack<>();
        ListNode cur = head;
        int size = 0;
        while (cur != null) {
            stack.push(cur);
            size++;
            cur = cur.next;
        }
        cur = head;
        for (int i = 0; i < size / 2; i++) {
            ListNode node = stack.pop();
            if (node.val != cur.val) {
                return false;
            }
            cur = cur.next;
        }
        return true;
    }

    public static void main(String[] args) {
        int[] arr = {1, 0, 0};
        ListNode head = new ListNode(arr);
        System.out.println(isPalindrome(head));
    }


}
